module MC.Order {
	export class Show {
		public constructor() {
			this.id = MC.get('id');
			MC.apiD('/api/order/bale/detail', {
				id: this.id
			}, (data: any) => {
				this.init(data);
			});
		}
		private id: string = '';
		private imgDetails: Array<any>;
		private data: any = null;
		private imgs: any = [];
		private table: MC.Order.Table = new MC.Order.Table($('#sizelistDiv'));
		private costlist: MC.Order.Table = new MC.Order.Table($('#costlist'));
		private init(data: any) {
			let mthis = this;
			this.data = data;
			console.log(data);
			$('.bigImg img').attr('src', data.img);
			$('.bigImg img').attr('alt', '主图');
			this.imgDetails = JSON.parse(data.imgDetails);
			this.imgDetails.push({
				name: '主图',
				src: data.img
			});
			this.imgs.push(data.img);

			this.showImgarray();
			$('#orderShowPage').on('click', 'img[alt]', function () {
				let img = $(this).attr('src');
				MC.msg.Image(img, mthis.imgs);
			});
			$('.status').text(data.status);

			$('.ordername').html(data.name);
			//    $('.level').html(data.level);

			if (data.is_rob == 1) {
				$('.bond').html('¥' + data.bond + '元');
			} else {
				$('.bondli').hide();
				$('.order_isrob').show();
			}
			if (data.ismy) {
				$('#orderJingxuan').show();
				$('.ordername').append(`
				<a class="editOrder" href="/h5/index/addOrder.html?id=`+ this.id + `">编辑</a>
				`);
			} else {
				$('#orderShowApply').show();
			}

			$('.styleNo').text(data.styleNo);
			$('.styleName').text(data.styleName);
			$('.scence').text(data.scence);
			$('.num').text(data.num);

			$('.money').text(data.money);
			$('.period').text(data.period);
			$('.material').text(data.material);
			$('.tech').text(data.tech);

			$('.design').text(data.design);
			$('.style').text(data.style);
			$('.orderType').text(data.orderType);
			$('#orderShowSample .grapp .grapcount').text(data.grapCount);
			if(data.grapCount>0){
				$('#orderShowSample .ordername .editOrder').attr('href',null);
				$('#orderShowSample .ordername .editOrder').addClass('jinzhi');
				$('#orderShowSample .ordername .editOrder').text('已经有人抢单,禁止编辑');
			}


			$('.proType').text(data.proType);
			$('.region').text(data.region);
			$('.proWay').text(data.proWay);
			$('.outTypes').text(data.outTypeStr);
			$('.cate').text(data.cate);
			if (data.detail !== '') {
				$('.detail').text(data.detail);
			} else {
				$('.detailDiv').hide();
			}





			if (data.stuff && data.stuff != '') {
				let stuff = JSON.parse(data.stuff);
				for (let i = 0; i < stuff.length; i++) {
					let one = stuff[i];
					let li = `<tr class="stufftd stuff1">
							<td>
								<span class="input">`+ one.key + `</span>
							</td>
							<td class="right">
								<span class="input">`+ one.val + `</span>
							</td> 
						</tr>`;
					$('.stuffDiv .tableDiv tbody').append(li);
				}
			} else {
				$('.stuffDiv').hide();
			}

			if (data.deplete && data.deplete != '') {
				let deplete = JSON.parse(data.deplete);
				for (let i = 0; i < deplete.length; i++) {
					let one = deplete[i];
					let li = `<tr class="depletetd deplete1">
                    <td>
                        <span class="input">`+ one.name + `</span>
                    </td>
                    <td class="right">
                        <span class="input">`+ one.size + `</span>
                    </td>
                    <td>
                        <span class="input">`+ one.num + `</span>
                    </td>
                    <td class="right">
                        <span class="input">`+ one.remark + `</span>
                    </td>
                </tr>`;
					$('.depletetdDiv .tableDiv tbody').append(li);
				}
			} else {
				$('.depletetdDiv').hide();
			}








			if (data.imgDetails && data.imgDetails !== '') {
				let imgDetails = JSON.parse(data.imgDetails);
				for (let i = 0; i < imgDetails.length; i++) {
					let one = imgDetails[i];
					let li = `<li>
								<img src="`+ one.src + `" alt="` + one.name + `" class="img"/>
								<h3 class="alt">`+ one.name + `</h3>
							</li>`;
					$('.piclist .ul').append(li);
				}
			}

			if (data.sizelist && data.sizelist !== '') {
				this.table.init();
				this.table.readOnly = true;
				this.table.setData(data.sizelist);
				this.table.create();
			}


			if (data.costlist && data.costlist !== '') {
				this.costlist.hangText = false;
				this.costlist.lieText = '自定义成本标题';
				this.costlist.init();
				this.costlist.readOnly = true;
				this.costlist.setData(data.costlist);
				this.costlist.create();
			}


			$('#orderJingxuan').click(() => {
				window.open('/h5/order/orderXuanze.html?bale=' + this.id, '_self');
			});

			$('#orderShowApply').click( ()=>{
				window.open('/h5/order/orderParam.html?id=' + this.id, '_self');
			});

		}

		private showImgarray() {
			let li = '';
			for (let i = 0; i < this.imgDetails.length && i < 3; i++) {
				li += '<li><img src=' + MC.pImg(this.imgDetails[i].src) + ' alt="' + this.imgDetails[i].name + '"></li>';
			}
			for (let i = 0; i < this.imgDetails.length; i++) {
				this.imgs.push(MC.pImg(this.imgDetails[i].src));
			}
			$('.smallImg ul').html(li);
		}




	}
}